// 封装一些方法
import config from './config'

export  function showSuccess(text){
	wx.showToast({
	  title: text,
	  icon: 'success',
	  duration: 2000
	})
}

export function showModel(title,content){
	wx.showModal({
	  title: title,
	  content: content,
	  showCancel:false
	})
}
	
//封装前端向后端发起request请求方法
function request(url,method,data){
	return new Promise(
		(resolve,reject) => {
			wx.request({
				//config.host指config.js里的host
				url:config.host + url,
				method:method,
				data:data,
				success:function(res){
					console.log("请求成功，在前端打印的信息",res)				
					if(res.data.code == 0){
						//pending变成resolved
						//第一个data是指res请求到的返回值
						resolve(res.data.data)
					}else{
						//pending变成rejected
						reject(res.data)
					}
				}
			})
		}
	)
}

//封装get方法
export function get(url,data){
	return request(url,"GET",data)
}
//封装post方法
export function post(url,data){
	return request(url,"POST",data)
}
